﻿using System;
using System.IO;
using Core.IocHelpers;
using System.Linq;

namespace Core.Infrastructure
{
  ///<summary>Related to .NET</summary>
  [AutoRegister]
  public class Framework : IFramework
  {
    #region IFramework Members

    ///<summary>Verify that we have .NET 3.5</summary>
    ///<returns></returns>
    public bool IsVersion4(out string message)
    {
      var path = Environment.ExpandEnvironmentVariables("%windir%") + @"\Microsoft.NET\Framework";
      var folderOkay = Directory
        .EnumerateFileSystemEntries(path, "v4.0.*", SearchOption.TopDirectoryOnly)
        .Any();

      message = string.Format(
            "Sorry, .NET Framework 4.0 is required and does not appear to be installed on this computer.\nPath not found: {0}",
            path);

      return folderOkay;
    }

    #endregion
  }

  [AutoRegisterable]
  public interface IFramework
  {
    ///<summary>Verify that we have .NET 3.5</summary>
    ///<returns></returns>
    bool IsVersion4(out string message);
  }
}